import { useDark } from "@/hooks/useDark";
import { selectTheme } from "@/store/reducer/themeSlice";
import { theme } from "antd";
import { shallowEqual, useSelector } from "react-redux";

export const useTheme = () => {
  const { primaryColor } = useSelector(selectTheme, shallowEqual);
  const { isDark } = useDark();

  // 切换暗黑模式
  const body = document.querySelector("body");
  if (body) body.className = isDark ? "dark" : "";

  // antd模式切换
  const themes = {
    algorithm: isDark ? theme.darkAlgorithm : theme.defaultAlgorithm,
    token: {
      colorPrimary: primaryColor,
    },
  };

  return themes;
};

export default useTheme;
